from collections import defaultdict
import configparser
import os
from pprint import pprint

env = os.environ.get("ZHUPU", "dev")
config_dir = os.path.join("/app", f"configs/{env}")


#####################################DB_CONFIG#####################################################

db_config = configparser.ConfigParser()
db_config.read(os.path.join(config_dir, "database.ini"))
db_config_dict = defaultdict(dict)
for section in db_config.sections():
    for k, v in db_config.items(section):
        db_config_dict[section][k] = v
        os.environ[f"{section}_{k}"] = v

DB_MYSQL_CONFIG = {
    "connections": {
        "default": {
            'engine': 'tortoise.backends.mysql',
            "credentials": {
                'host': db_config_dict["mysql"]["host"],
                'user': db_config_dict["mysql"]["user"],
                'password': db_config_dict["mysql"]["password"],
                'port': db_config_dict["mysql"]["port"],
                'database': db_config_dict["mysql"]["database"],
            }
        },
    },
    "apps": {
        "base": {
                "models":["models.base_model", "models.user_model", "aerich.models"], 
                 "default_connection": "default"
                 },
    },
    'use_tz': False,
    'timezone': 'Asia/Shanghai'
}

DB_REDIS_CONFIG = {
    'host': db_config_dict["redis"]["host"],
    'port': db_config_dict["redis"]["port"],
    'db1': db_config_dict["redis"]["db1"],
    'db2': db_config_dict["redis"]["db2"],
}


if __name__ == "__main__":
    pprint(DB_REDIS_CONFIG)